package com.yuanbao.base.response;

import com.yuanbao.base.enums.ResponseCodeEnum;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

@ApiModel
public class Message<T> implements Serializable {
    @Setter
    @Getter
    @ApiModelProperty("-1:未知错误 200:成功 400:参数异常 403:没有权限 404:资源未找到 600:业务错误")
    private int code;

    @Setter
    @Getter
    @ApiModelProperty("提示消息")
    private String message;

    @Setter
    @Getter
    @ApiModelProperty("数据")
    private T data;

    public Message() {
        this.code = ResponseCodeEnum.SUCCESS.getCode();
        this.message = "成功";
    }

    public Message(T data) {
        this.code = ResponseCodeEnum.SUCCESS.getCode();
        this.data = data;
    }

    public Message(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Message(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Boolean success() {
        return ResponseCodeEnum.SUCCESS.getCode() == 200;
    }
}